<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.baoku.wap.dao.*"  %>
<%@ page import="com.baoku.wap.entity.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%  
	// 数据的检查就在这个页面做掉了,UserFactory不负责数据检查. 用户名长度4-12,密码长度6-12;且不含中文
	String id = request.getParameter("id");
	if (id == null || id == ""){
		response.sendRedirect("reg_err.jsp?msg=1");
		return;
	}
	
	String password = request.getParameter("password");
	if (password == null || password == ""){
		response.sendRedirect("reg_err.jsp?msg=1");
		return;
	}
	
	int i = id.length();
	if( i<4 || i>12) {
		response.sendRedirect("reg_err.jsp?msg=3");
		return;
	}
	
	int j = password.length();
	if( j<6 || i>12) {
		response.sendRedirect("reg_err.jsp?msg=4");
		return;
	}
	
	String mail1 = request.getParameter("email1");
	String mail2 = request.getParameter("email2");
	String mail3 = request.getParameter("email3");
	String mail = mail1 + "@" + mail2 + "." + mail3;
	
	User user = new User();
	user.setId(id);
	user.setPassword(password);
	user.setEmail(mail);
	
	if(new UserFactory().saveUser(user)){
		session.setAttribute("login","true");
		session.setAttribute("id",user.getId());
		response.sendRedirect("reg_succes.jsp");
	}else {
		response.sendRedirect("reg_err.jsp?msg=2");
	}
%>